$(document).ready(function () {
    $('#loginForm')
        .bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
                valid: 'glyphicon glyphicon-ok',
                invalid: 'glyphicon glyphicon-remove',
                validating: 'glyphicon glyphicon-refresh'
            },
            fields: {
                username: {
                    message: 'The username is not valid',
                    validators: {
                        notEmpty: {
                            message: 'The username is required and can\'t be empty'
                        },
                        stringLength: {
                            min: 6,
                            max: 30,
                            message: 'The username must be more than 6 and less than 30 characters long'
                        },
                        regexp: {
                            regexp: /^[a-zA-Z0-9_\.]+$/,
                            message: 'The username can only consist of alphabetical, number, dot and underscore'
                        }
                    }
                },
                password: {
                    validators: {
                        notEmpty: {
                            message: 'The password is required and can\'t be empty'
                        }
                    }
                }
            }
        })
        .on('success.form.bv', function (e) {
            var baseurl = "http://10.222.29.195:8999/";
            let username = $("#inputUsername").val();
            let password = $("#inputPassword").val();
            $.ajax({
                url: baseurl + "login",
                type: "POST",
                data: {"username": username, "password": password},
                xhrFields: {
                    withCredentials: true
                },
                crossDomain: true,
                success: function (data) {
                    if (data.content == true) {
                        window.location = "http://10.222.29.195:9000/index.html"
                    }else{
                        showInfo("用户名密码错误");
                    }

                }
            });

            e.preventDefault();

        });

    function showInfo(msg) {
        $("#div_info").text(msg);
        $("#modal_info").modal('show');
    }


});